/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import java.awt.Image;
import java.awt.Toolkit;
import static java.lang.Thread.sleep;
import java.net.URL;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;

/**
 *
 * @author Iserj
 */
public class principal extends javax.swing.JFrame {

    /**
     * Creates new form principal
     */
    public principal() {
        initComponents();
        
        setIcon();
        
        this.setExtendedState(MAXIMIZED_BOTH);

       // lbl_imagemfundo.setSize(this.getWidth(), this.getHeight());
        new Thread() {
            @Override
            public void run() {
                for (;;) {
                    GregorianCalendar Calendar = new GregorianCalendar();

                    int dia = Calendar.get(GregorianCalendar.DAY_OF_MONTH);

                    Calendar data = Calendar.getInstance();
                    String mes = "";
                    switch (data.get(Calendar.MONTH) + 1) {
                        case 1:
                            mes = "Janeiro";
                            break;
                        case 2:
                            mes = "Fevereiro‎";
                            break;
                        case 3:
                            mes = "Março‎";
                            break;
                        case 4:
                            mes = "Abril‎";
                            break;
                        case 5:
                            mes = "Maio";
                            break;
                        case 6:
                            mes = "Junho";
                            break;
                        case 7:
                            mes = "Julho";
                            break;
                        case 8:
                            mes = "Agosto";
                            break;
                        case 9:
                            mes = "Setembro";
                            break;
                        case 10:
                            mes = "Outubro";
                            break;
                        case 11:
                            mes = "Novembro";
                            break;
                        case 12:
                            mes = "Dezembro";
                            break;
                        default:
                            mes = "Mês Inválido";
                            break;
                    }

                    int ano = Calendar.get(GregorianCalendar.YEAR);

                    lbl_data.setText("" + dia + " de " + mes + " de " + ano);

                    int hora = Calendar.get(GregorianCalendar.HOUR_OF_DAY);
                    int min = Calendar.get(GregorianCalendar.MINUTE);
                    int seg = Calendar.get(GregorianCalendar.SECOND);

                    final String horaString;
                    final String minString;
                    final String segString;

                    if (hora < 10) {
                        horaString = "0" + hora;
                    } else {
                        horaString = "" + hora;
                    }

                    if (min < 10) {
                        minString = "0" + min;
                    } else {
                        minString = "" + min;
                    }

                    if (seg < 10) {
                        segString = "0" + seg;
                    } else {
                        segString = "" + seg;
                    }

                    lbl_hora.setText(horaString + ":" + minString + ":" + segString);
                    try {
                        sleep(1000);
                    } catch (InterruptedException ex) {
                        System.out.println("Ocorreu um erro no: " + ex.getMessage());
                    }
                }

            }
        }
                .start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pri_painel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbl_hora = new javax.swing.JLabel();
        lbl_data = new javax.swing.JLabel();
        pri_fer = new javax.swing.JToolBar();
        pri_ferBtn1 = new javax.swing.JButton();
        pri_ferBtn2 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jButton3 = new javax.swing.JButton();
        btn_relatorio = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jButton4 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton5 = new javax.swing.JButton();
        pri_bar = new javax.swing.JMenuBar();
        pri_bar_cad = new javax.swing.JMenu();
        mnuCadCli = new javax.swing.JMenuItem();
        mnuCadEqu = new javax.swing.JMenuItem();
        pri_bar_efe = new javax.swing.JMenu();
        pri_bar_tro = new javax.swing.JMenu();
        pri_bar_sai = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        pri_painel.setToolTipText("");
        pri_painel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        pri_painel.setMaximumSize(new java.awt.Dimension(5555, 5555));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/bosch.png"))); // NOI18N

        javax.swing.GroupLayout pri_painelLayout = new javax.swing.GroupLayout(pri_painel);
        pri_painel.setLayout(pri_painelLayout);
        pri_painelLayout.setHorizontalGroup(
            pri_painelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pri_painelLayout.createSequentialGroup()
                .addContainerGap(863, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(56, 56, 56))
        );
        pri_painelLayout.setVerticalGroup(
            pri_painelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pri_painelLayout.createSequentialGroup()
                .addContainerGap(531, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );

        lbl_hora.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbl_hora.setMaximumSize(new java.awt.Dimension(108, 22));
        lbl_hora.setMinimumSize(new java.awt.Dimension(108, 22));
        lbl_hora.setPreferredSize(new java.awt.Dimension(108, 22));

        lbl_data.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbl_data.setToolTipText("Data");
        lbl_data.setMaximumSize(new java.awt.Dimension(108, 22));
        lbl_data.setMinimumSize(new java.awt.Dimension(108, 22));
        lbl_data.setName(""); // NOI18N
        lbl_data.setPreferredSize(new java.awt.Dimension(108, 22));

        pri_fer.setFloatable(false);
        pri_fer.setRollover(true);
        pri_fer.setPreferredSize(new java.awt.Dimension(800, 25));

        pri_ferBtn1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cadastrar_cli.png"))); // NOI18N
        pri_ferBtn1.setText("Cadastrar Cliente ");
        pri_ferBtn1.setFocusable(false);
        pri_ferBtn1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pri_ferBtn1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        pri_ferBtn1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pri_ferBtn1MouseClicked(evt);
            }
        });
        pri_ferBtn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pri_ferBtn1ActionPerformed(evt);
            }
        });
        pri_fer.add(pri_ferBtn1);

        pri_ferBtn2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cadastrar_equi.png"))); // NOI18N
        pri_ferBtn2.setText("Cadastrar Equipamento");
        pri_ferBtn2.setFocusable(false);
        pri_ferBtn2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pri_ferBtn2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        pri_ferBtn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pri_ferBtn2ActionPerformed(evt);
            }
        });
        pri_fer.add(pri_ferBtn2);
        pri_fer.add(jSeparator4);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/efetuar_venda.png"))); // NOI18N
        jButton3.setText("Efetuar Venda");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        pri_fer.add(jButton3);

        btn_relatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/relatorio.png"))); // NOI18N
        btn_relatorio.setText("Controle de venda");
        btn_relatorio.setToolTipText("");
        btn_relatorio.setFocusable(false);
        btn_relatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btn_relatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btn_relatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_relatorioActionPerformed(evt);
            }
        });
        pri_fer.add(btn_relatorio);
        pri_fer.add(jSeparator3);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/troca.png"))); // NOI18N
        jButton4.setText("Trocar Equipamento");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        pri_fer.add(jButton4);
        pri_fer.add(jSeparator1);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/sair.png"))); // NOI18N
        jButton5.setText("Sair");
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        pri_fer.add(jButton5);

        pri_bar_cad.setText("Cadastrar ");

        mnuCadCli.setText("Cliente");
        mnuCadCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadCliActionPerformed(evt);
            }
        });
        pri_bar_cad.add(mnuCadCli);

        mnuCadEqu.setText("Equipamento");
        mnuCadEqu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadEquActionPerformed(evt);
            }
        });
        pri_bar_cad.add(mnuCadEqu);

        pri_bar.add(pri_bar_cad);

        pri_bar_efe.setText("Efetuar Venda");
        pri_bar_efe.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pri_bar_efeMouseClicked(evt);
            }
        });
        pri_bar_efe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pri_bar_efeActionPerformed(evt);
            }
        });
        pri_bar.add(pri_bar_efe);

        pri_bar_tro.setText("Trocar Equipamento ");
        pri_bar_tro.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pri_bar_troMouseClicked(evt);
            }
        });
        pri_bar_tro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pri_bar_troActionPerformed(evt);
            }
        });
        pri_bar.add(pri_bar_tro);

        pri_bar_sai.setText("Sair");
        pri_bar_sai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pri_bar_saiMouseClicked(evt);
            }
        });
        pri_bar_sai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pri_bar_saiActionPerformed(evt);
            }
        });
        pri_bar.add(pri_bar_sai);

        setJMenuBar(pri_bar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pri_fer, javax.swing.GroupLayout.PREFERRED_SIZE, 832, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_data, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addComponent(lbl_hora, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(pri_painel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lbl_data, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pri_fer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                    .addComponent(lbl_hora, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pri_painel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lbl_hora.getAccessibleContext().setAccessibleName("Dia mês Ano ");
        lbl_data.getAccessibleContext().setAccessibleName("xx-xx-xxxx");

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void pri_ferBtn2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pri_ferBtn2ActionPerformed
        cadastroEquipamento chama = new cadastroEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);
    }//GEN-LAST:event_pri_ferBtn2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        trocaEquipamento chama = new trocaEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        System.exit(0);
    }//GEN-LAST:event_jButton5MouseClicked

    private void pri_ferBtn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pri_ferBtn1ActionPerformed
        cadastroCliente chama = new cadastroCliente();
        pri_painel.add(chama);
        chama.setVisible(true);
    }//GEN-LAST:event_pri_ferBtn1ActionPerformed

    private void pri_ferBtn1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pri_ferBtn1MouseClicked
        new cadastroCliente().setVisible(true); // esta ação abre a tela       

    }//GEN-LAST:event_pri_ferBtn1MouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Você realmente deseja finalizar o sistema?", "Finalizando o Sistema", JOptionPane.YES_NO_OPTION);
        if (resposta == 0) {
            System.exit(0);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jButton5ActionPerformed

    private void mnuCadCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadCliActionPerformed
        cadastroCliente chama = new cadastroCliente();
        pri_painel.add(chama);
        chama.setVisible(true);//chama a tela de cadastro de cliente
    }//GEN-LAST:event_mnuCadCliActionPerformed

    private void mnuCadEquActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadEquActionPerformed
        cadastroEquipamento chama = new cadastroEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);        // Chuama a tela de cadastro de equipamento
    }//GEN-LAST:event_mnuCadEquActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        vendaEquipamento chama = new vendaEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);        // chama tela de venda de equipamento
    }//GEN-LAST:event_jButton3ActionPerformed

    private void pri_bar_efeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pri_bar_efeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pri_bar_efeActionPerformed

    private void pri_bar_efeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pri_bar_efeMouseClicked
        vendaEquipamento chama = new vendaEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);        // chama tela de venda de equipamento
    }//GEN-LAST:event_pri_bar_efeMouseClicked

    private void pri_bar_troActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pri_bar_troActionPerformed
        trocaEquipamento chama = new trocaEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);// chama a tela de trocar equipamento
    }//GEN-LAST:event_pri_bar_troActionPerformed

    private void pri_bar_troMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pri_bar_troMouseClicked
        trocaEquipamento chama = new trocaEquipamento();
        pri_painel.add(chama);
        chama.setVisible(true);        //chama tela de troca de equipamento
    }//GEN-LAST:event_pri_bar_troMouseClicked

    private void pri_bar_saiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pri_bar_saiActionPerformed

    }//GEN-LAST:event_pri_bar_saiActionPerformed

    private void pri_bar_saiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pri_bar_saiMouseClicked
        int resposta = JOptionPane.showConfirmDialog(null, "Você realmente deseja finalizar o sistema?", "Finalizando o Sistema", JOptionPane.YES_NO_OPTION);
        if (resposta == 0) {
            System.exit(0);
        }
    }//GEN-LAST:event_pri_bar_saiMouseClicked

    private void btn_relatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_relatorioActionPerformed
        relatorio chama = new relatorio();
        pri_painel.add(chama);
        chama.setVisible(true);
    }//GEN-LAST:event_btn_relatorioActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_relatorio;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JLabel lbl_data;
    private javax.swing.JLabel lbl_hora;
    private javax.swing.JMenuItem mnuCadCli;
    private javax.swing.JMenuItem mnuCadEqu;
    private javax.swing.JMenuBar pri_bar;
    private javax.swing.JMenu pri_bar_cad;
    private javax.swing.JMenu pri_bar_efe;
    private javax.swing.JMenu pri_bar_sai;
    private javax.swing.JMenu pri_bar_tro;
    private javax.swing.JToolBar pri_fer;
    private javax.swing.JButton pri_ferBtn1;
    private javax.swing.JButton pri_ferBtn2;
    private javax.swing.JPanel pri_painel;
    // End of variables declaration//GEN-END:variables

    private void setIcon() {
        
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/imagens/login_ferramenta.png")));  
    }
}
